package com.supercube.common.controller;

import com.supercube.common.utils.*;
import com.supercube.system.domain.UserToken;
import org.springframework.stereotype.Controller;
import com.supercube.system.domain.UserDO;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller
public class BaseController {
	public UserDO getUser() {
		return ShiroUtils.getUser();
	}

	public Long getUserId() {
		return getUser().getUserId();
	}

	public String getUserIdStr() {
		return getUserId().toString();
	}

	public String getUsername() {
		return getUser().getUsername();
	}

	public String getCurrentTime(){
		return TimeUtils.getCurrentTime();
	}

	public String randomUUID(){
		return UUID.randomUUID().toString();
	}

	/**
	 * 是否为空
	 * @param id id
	 * @return Empty is true | notEmpty is false
	 */
	public boolean isEmpty(String id) {
		if (StringUtils.isEmpty(id)) {
			return true;
		}
		return false;
	}

	public PageUtils getPageList(Map<String, Object> params , IPageDefine pageDefine){
		PageUtils pageUtils = null;
		try {
			//获取分页参数(格式：{limit=10, offset=0} )
			Query query = Query.getPageParams(params);

			//查询分页列表数据
			List<?> dictList = pageDefine.getPageRows(query);

			//获取页码参数
			pageUtils = new PageUtils(dictList, query);

		} catch (Exception e) {
			e.printStackTrace();
		}

		return pageUtils;
	}
}